# -*- coding: utf-8 -*-  
from bug_page import *
from mongodb import *
from github import *


class test_all(object):
	
	def __init__(self):
		#url1="https://github.com/composer/satis/labels/bug"
		#url1="https://github.com/franzliedke/studio/labels/bug"
		url1="https://github.com/SpiderLabs/ModSecurity/labels/Bug"
		self.open_bugnum= skipspace(getpage_spider(url1))

		
		#url2="https://github.com/composer/satis/issues?q=label%3Abug+is%3Aclosed"
		url2="https://github.com/SpiderLabs/ModSecurity/issues?q=label%3Abug+is%3Aclosed"
		self.close_bugnum= skipspace(getpage_spider(url2))

		
	def get_closeitem(self):
		close_bugnum=self.close_bugnum
		item_close=[]
		
		for i in close_bugnum:
			#url="https://github.com/composer/satis/issues/{}".format(i)
			url="https://github.com/SpiderLabs/ModSecurity/issues/{}".format(i)
			item_close.append(spider(url,"close",i))
		return item_close
			
	def get_openitem(self):

		open_bugnum=self.open_bugnum
	
		item_open=[]
		for i in open_bugnum:
			#url="https://github.com/composer/satis/issues/{}".format(i)
			url="https://github.com/SpiderLabs/ModSecurity/issues/{}".format(i)	
			
			item_open.append(spider(url,"open",i))
			
			#print item_open[0].get("staus")

		return item_open

	


class mongo_test(unittest.TestCase):
	
	def setUp(self):


		self.db_api=mongo_store("127.0.0.1",27017,"db_bug","securty_bug")
		self.item_open=test_all().get_openitem()
		self.item_close=test_all().get_closeitem()

	def test(self):
		db_api= self.db_api
		
		item_open=self.item_open
	
		item_close=self.item_close
	
		for each in item_close:
			db_api.add(each)

		for each1 in item_open:
			db_api.add(each1)





if __name__ == '__main__':
	
	unittest.main()